<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>九宫格抽奖</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f0f0f0;
            color: #333;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
        }
        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 80%;
            max-width: 600px;
        }
        h1 {
            text-align: center;
            margin-bottom: 20px;
        }
        .grid-container {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 10px;
            margin-bottom: 20px;
        }
        .grid-item {
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #f9f9f9;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 1.2em;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        .grid-item.highlight {
            background-color: #ffcc00;
        }
        .button-container {
            display: flex;
            justify-content: center;
            gap: 10px;
            margin-bottom: 20px;
        }
        .button-container button {
            padding: 10px 20px;
            border: 1px solid #ddd;
            background-color: #fff;
            cursor: pointer;
            border-radius: 5px;
        }
        .button-container button:hover {
            background-color: #f9f9f9;
        }
        .result {
            margin-top: 20px;
            text-align: center;
            font-size: 1.2em;
            color: #28a745;
        }
        .record-container {
            margin-top: 20px;
            width: 100%;
            max-height: 150px;
            overflow-y: auto;
            border: 1px solid #ddd;
            border-radius: 5px;
            padding: 10px;
        }
        .record-item {
            margin-bottom: 10px;
            font-size: 1em;
            color: #333;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>九宫格抽奖</h1>
        <div class="grid-container" id="grid-container">
            <div class="grid-item" data-index="0">一等奖</div>
            <div class="grid-item" data-index="1">二等奖</div>
            <div class="grid-item" data-index="2">三等奖</div>
            <div class="grid-item" data-index="3">四等奖</div>
            <div class="grid-item" data-index="4">五等奖</div>
            <div class="grid-item" data-index="5">六等奖</div>
            <div class="grid-item" data-index="6">七等奖</div>
            <div class="grid-item" data-index="7">八等奖</div>
            <div class="grid-item" data-index="8">谢谢参与</div>
        </div>
        <div class="button-container">
            <button id="start-button">开始</button>
            <button id="stop-button" disabled>暂停</button>
        </div>
        <div class="result" id="result"></div>
        <div class="record-container" id="record-container">
            <div class="record-item">抽奖记录：</div>
        </div>
    </div>

    <script>
        const gridContainer = document.getElementById('grid-container');
        const startButton = document.getElementById('start-button');
        const stopButton = document.getElementById('stop-button');
        const resultDiv = document.getElementById('result');
        const recordContainer = document.getElementById('record-container');
        let isRunning = false;
        let intervalId;
        let currentHighlightIndex = -1;

        startButton.addEventListener('click', function() {
            if (isRunning) return;
            isRunning = true;
            startButton.disabled = true;
            stopButton.disabled = false;
            resultDiv.textContent = '';
            intervalId = setInterval(highlightRandomItem, 100);
        });

        stopButton.addEventListener('click', function() {
            if (!isRunning) return;
            isRunning = false;
            clearInterval(intervalId);
            startButton.disabled = false;
            stopButton.disabled = true;
            const highlightedItem = gridContainer.querySelector('.highlight');
            if (highlightedItem) {
                resultDiv.textContent = `恭喜你，获得：${highlightedItem.textContent}`;
                addRecord(highlightedItem.textContent);
                highlightedItem.classList.remove('highlight');
            }
        });

        function highlightRandomItem() {
            const items = gridContainer.children;
            if (currentHighlightIndex !== -1) {
                items[currentHighlightIndex].classList.remove('highlight');
            }
            currentHighlightIndex = Math.floor(Math.random() * items.length);
            items[currentHighlightIndex].classList.add('highlight');
        }

        function addRecord(record) {
            const recordItem = document.createElement('div');
            recordItem.classList.add('record-item');
            recordItem.textContent = record;
            recordContainer.appendChild(recordItem);
        }
    </script>
</body>
</html>